<template>
  <div>
    <customDetailsTopbar :title="title" flag @back="back" />
    <div class="d-scroll listInner px-1">
      <div class="py-1 px-1 bg-white">
        <div v-for="(item, index) in descList" :key="index">
          <div>
            <custom-details-item :icon="item.icon" :label="item.label" :value="item.value">
              <template #valueSlot>
                <span v-if="item.label !== '附件' && item.label !== '监测报告'">{{ item.value }}</span>
                <template v-else>
                  <el-link type="primary" @click="openAttachPopUp(item.value)">查看</el-link>
                </template>
              </template>
            </custom-details-item>
          </div>
        </div>
      </div>
    </div>
    <attachPopUp ref="attachPopUp" />
  </div>
</template>

<script>
import commonList from '@/assets/mixin/commonList'

export default {
  mixins: [commonList],
  data() {
    return {
      form: {
        companyIds: '',
        pageNum: 1,
        pageSize: 10
      },
      descList: [],
      desListMap: {
        '排污许可证': [
          { label: '企业名称', fieldName: 'companyName', value: '', icon: '&#xe790;' },
          { label: '行业类别', fieldName: 'industryTypeName', value: '', icon: '&#xe634;' },
          { label: '许可证编号', fieldName: 'licenseNumber', value: '', icon: '&#xe696;' },
          { label: '管理级别', fieldName: 'manageLevel', value: '', icon: '&#xe6f7;' },
          { label: '发证机关', fieldName: 'sendDept', value: '', icon: '&#xe790;' },
          { label: '发证日期', fieldName: 'issueDate', value: '', icon: '&#xe617;' },
          { label: '有效期限', fieldName: 'yearsDiff', value: '', icon: '&#xe6e3;' },
          { label: '是否到期', fieldName: 'isdq', value: '', icon: '&#xe6a4;' },
          { label: '临期天数', fieldName: 'gqts', value: '', icon: '&#xe61c;' },
          { label: '创建时间', fieldName: 'updateTime', value: '', icon: '&#xe617;' }
        ],
        '监测信息': [
          { label: '企业名称', fieldName: 'companyName', value: '', icon: '&#xe790;' },
          { label: '委托检测机构名称', fieldName: 'organizationName', value: '', icon: '&#xe791;' },
          { label: '监测日期', fieldName: 'organizationTime', value: '', icon: '&#xe6f7;' },
          { label: '上传时间', fieldName: 'creationTime', value: '', icon: '&#xe6e3;' },
          { label: '监测报告', fieldName: 'shareAttachVos', value: '', uuid: '', icon: '&#xe677;' }
        ],
        '执行报告': [
          { label: '企业名称', fieldName: 'companyName', value: '', icon: '&#xe790;' },
          { label: '执行报告标题', fieldName: 'executiveReportTitle', value: '', icon: '&#xe791;' },
          { label: '报告类型', fieldName: 'executiveReportType', value: '', icon: '&#xe6f7;' },
          { label: '报告时间', fieldName: 'executiveReportTime', value: '', icon: '&#xe617;' },
          { label: '是否已公开', fieldName: 'isPub', value: '', icon: '&#xe6a4;' },
          { label: '公开网站地址', fieldName: 'pubWebUrl', value: '', icon: '&#xe6f7;' },
          { label: '创建时间', fieldName: 'creationTime', value: '', icon: '&#xe6e3;' },
          { label: '附件', fieldName: 'shareAttachVos', value: '', uuid: '', icon: '&#xe677;' }
        ]
      },
      title: '',
      titleMap: {
        '排污许可证': '排污许可证详情',
        '监测信息': '监测信息详情',
        '执行报告': '执行报告详情'
      },
      checkedArr: {
        '排污许可证': 0,
        '监测信息': 1,
        '执行报告': 2
      },
      checkedValue: 0
    }
  },
  mounted() {
    const { current, tag } = this.$route.query
    this.current = current || ''
    this.descList = this.desListMap[tag]
    this.title = this.titleMap[tag]
    this.checkedValue = this.checkedArr[tag]

    const data = this.$route.query
    // this.getDetail()
    this.descList.forEach((v) => {
      v.value = data[v.fieldName] !== '' ? data[v.fieldName] : '/'
      if (v.fieldName === 'attachName') {
        v.uuid = data.attachUuid
      }
    })
  },
  methods: {
    // 排污许可证详情
    // async getDetail() {
    //   const api = [
    //     HbPermitList,
    //     hbPermitDataInfoList,
    //     HbPermitExecutiveReportList]
    //   this.layout.showLoading()
    //   const { status, data } = await api[this.checkedValue](this.form)
    //   if (status === 0 && data) {
    //     this.descList.forEach((v) => {
    //       v.value = data.list[0][v.fieldName] !== '' ? data.list[0][v.fieldName] : '/'
    //       if (v.fieldName === '附件') {
    //         v.uuid = data.attachmentUuid
    //       }
    //     })
    //     this.layout.hideLoading()
    //   }
    // },
    back() {
      this.$router.push({
        path: '/staging/pollutionDischarge',
        query: { current: this.current, tag: this.$route.query.tag }
      })
    }
  }
}
</script>
